<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <!-- h5表单验证必要条件：
                1、必须包在form标签里面
                2、按钮必须是submit(或者说必须要触发表单提交才能生效) -->
    <form action="http://www.baidu.com" >
        账号：<input type="text" id="user" required pattern="1\d{10}">
        <input type="submit" onclick="val()" value="提交">
    </form>

    <script src="/网页展示/js/jquery-3.4.1.min.js"></script>
    <script>
        function val(){
            let input = $('#user')[0];//获取dom元素
            if(input.validity.valueMissing==true){
                input.setCustomValidity("账号不能为空") //设置
            }else if(input.validity.patternMismatch==true){
                input.setCustomValidity("账号格式不对")
            }else{
                input.setCustomValidity("")
            }

        }
    </script>
</body>
</html>